import store from '@/store/index.js'
const baseurl = 'https://h900vpfy.vip6.hlidc.cn/api/'
// const baseurl = 'https://liy.c.hlidc.cn/api/'
import {
	commonloginwxLogin
} from '../untils/api'
export default function http(url, data, method = 'POST') {
	return new Promise((resolve) => {
		var requestTask = uni.request({
			url: baseurl + url,
			data,
			method,
			header: {
				'Content-Type': 'application/json',
				"token": uni.getStorageSync('token')
			},
			success: (res) => {
				console.log(res.data);
				uni.hideLoading();
				resolve(res.data)
				if (res.data.code == 401) {
					/*uni.showModal({
						title: '提示',
						content: '未登录/登录信息已过期，点击登录重新登录！',
						confirmText:'登录',
						success: function (res) {
							if (res.confirm) {

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});*/
					uni.login({
						provider: 'weixin',
						onlyAuthorize: true, // 微信登录仅请求授权认证
						success: (event) => {
							console.log(event.code)
							commonloginwxLogin({
								code: event.code
							}).then(res => {
								uni.setStorageSync('token', res.data.token);
								uni.setStorageSync('userid', res.data.id);
								/*uni.reLaunch({
									url:'/pages/index/index'
								});*/
							})
						},
						fail: function (err) {
							console.log(err);
						}
					});

					// //跳转登录页
					// var jump = uni.getStorageSync('jump')
					// if (!jump) {
					// 	setTimeout(() => {
					// 		uni.navigateTo({
					// 			url: '/pagesA/denglu/denglu'
					// 		})
					// 	}, 100)
					// 	uni.setStorageSync('jump', 'true')
					// 	//登录页onload写uni.removeStorageSync('jump')
					// }
					// 	//跳转登录页结束

					//  //全局弹窗
					// store.commit('tt')
					// 	 //全局弹窗结束
				}
				if (res.data.code == '1') {
					uni.hideLoading();
				} else {
					uni.hideLoading();
					uni.$u.toast(res.data.msg)
				}
			},
			fail: (err) => {
				console.log(err);
			}
		})
	})

}
